package com.woniu.service;

import com.woniu.dao.RbacMenuDao;
import com.woniu.entity.RbacMenu;
import com.woniu.entity.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author WenXin
 * @version 1.0
 * @description: TODO
 * @date 2022/9/9 11:43
 */
@Service
public class RbacMenuServiceImpl implements RbacMenuService {
    @Autowired
    RbacMenuDao rbacMenuDao;

    @Override

    public ResponseEntity findAll() {
        List<RbacMenu> list = rbacMenuDao.findAll();
        return new ResponseEntity(list);
    }

    @Override
    public ResponseEntity editOne(RbacMenu rbacMenu) {
        int i = rbacMenuDao.editOne(rbacMenu);
        if (i > 0) {
            return new ResponseEntity(200, "修改" + rbacMenu.getMenuname() + "成功");
        } else {
            return new ResponseEntity(500, "修改" + rbacMenu.getMenuname() + "失败");
        }
    }

    @Override
    public ResponseEntity updateMenu(int id, Integer fid) {
        if (fid == 0) {
            fid = null;
        }
        int i = rbacMenuDao.updateMenu(id, fid);
        if (i > 0) {
            return new ResponseEntity(200, "拖拽菜单成功");
        } else {
            return new ResponseEntity(500, "拖拽菜单失败");
        }
    }

    @Override
    public ResponseEntity showMenuByUserId(int id) {
        List<RbacMenu> list = rbacMenuDao.showMenuByUserId(id);
        return new ResponseEntity(list);
    }

    @Override
    public ResponseEntity getMenuIdUserId(int id) {
        List<RbacMenu> list = rbacMenuDao.getMenuIdUserId(id);
        return new ResponseEntity(list);
    }
}
